// 导入数据库操作模块
const db = require('../db/index')
exports.addGoods = (req,res)=>{
    // 得到发送过来的商品id、intorduce、pictureUrl、morePictureUrl、price、type、age、销量sales默认10
    const id=req.body.id;
    const intorduce=req.body.intorduce;
    const picture = req.body.pictureUrl;
    console.log(picture);//url(http)格式
    const detailPics=req.body.morePictureUrl;
    console.log(detailPics);
    const price = req.body.price;
    const type=req.body.type;
    const age = req.body.age;
    const sales = 10;
    db.query(`insert into goods values('${picture}','${intorduce}','${price}','${age}','${sales}','${type}','${id}');insert into goodsdetail values('${id}','${detailPics}')`,(err,results)=>{
        // 执行SQL语句失败
        if(err) return res.send(err)
        // 调用res.send将信息响应给客户端
        res.send({
            status:200,
            message:'商品添加成功',
            result:results
        })
       })
}